local p = Package("yxt")
p.extensionName = "project_moon"

local U = require "packages/utility/utility"


Fk:loadTranslationTable{
  ["yxt"] = "异想体",
}



local yxt__modan = General:new(p, "yxt__modan", "Lobot", 3, 3,General.Male)

Fk:loadTranslationTable{
  ["yxt__modan"] = "魔弹射手",
  ["#yxt__modan"] = "魔弹",
  ["designer:yxt__modan"] = "Dc.pi_7",
  ["cv:yxt__modan"] = "无",
  ["illustrator:yxt__modan"] = "月亮计划",
}


local modan = fk.CreateTriggerSkill{
  name = "modan",
  frequency = Skill.Compulsory,
  events ={fk.TargetSpecified},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.is_damage_card and data.card.name ~= "modan__slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    local twt = {}



    local modan = Fk:cloneCard("modan__slash")
    for _, p in ipairs(room.alive_players) do
      if not (p == player or player:isProhibited(p, modan)) then
        table.insert(targets, p.id)
        if p:getMark("@@weituo_target-round") == 1 then
          table.insert(twt, p.id)
        end
      end
    end
    if #targets == 0 then return false end
    AimGroup:cancelTarget(data, data.to)
    if #twt == 0 then
      local target = room:askForChoosePlayers(player,targets,1,1,"#modan-choose",self.name,false)
      local card = Fk:cloneCard("modan__slash")
      card.skillName = self.name
      room:useCard({
        from = player.id,
        tos = {target},
        card = card,
      })
    else
      if #twt == 1 then
        local target = twt
        local card = Fk:cloneCard("modan__slash")
        card.skillName = self.name
        room:useCard({
          from = player.id,
          tos = {target},
          card = card,
        })
      else
        local target = room:askForChoosePlayers(player,twt,1,1,"#modan-choose",self.name,true)
        local card = Fk:cloneCard("modan__slash")
        card.skillName = self.name
        room:useCard({
          from = player.id,
          tos = {target},
          card = card,
        })
      end
    end
    return true
  end,
}

local weituo = fk.CreateTriggerSkill{
  name = "weituo",
  attached_skill_name = "weituo&",
}

local weituo_active = fk.CreateActiveSkill{
  name = "weituo&",
  anim_type = "special",
  target_num = 1,
  prompt = "#weituo&",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) ~= 999
  end,
  card_filter = function(self, to_select)
    return not Self:prohibitDiscard(to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("@@weituo_target-round") ~= 1 then
      local target = Fk:currentRoom():getPlayerById(to_select)
      if target.hp == #selected_cards then
        return not (Fk:currentRoom():getPlayerById(to_select):hasSkill("weituo"))
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = {}
    for _, play in ipairs(room.alive_players) do
      if play:hasSkill("weituo") then
        table.insert(targets, play.id)
      end
    end
    if #targets == 0 then return false end
    if #targets == 1 then
      local target = room:getPlayerById(targets[1])
      room:setPlayerMark(room:getPlayerById(effect.tos[1]),"@@weituo_target-round",1)
      room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, "weituo")
    else
      local target = room:askForChoosePlayers(player,targets,1,1,"#weituo-choose",self.name,true)
      target = room:getPlayerById(target[1])
      room:setPlayerMark(room:getPlayerById(effect.tos[1]),"@@weituo_target-round",1)
      room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, "weituo")
    end
  end,
}

Fk:addSkill(weituo_active)



yxt__modan:addSkill(modan)
yxt__modan:addSkill(weituo)

Fk:loadTranslationTable{
  ["modan"] = "魔弹",
  [":modan"] = "锁定技，当你使用魔弹外的伤害类牌指定目标时，取消之，然后你选择一名角色，视为对其使用一张【魔弹】，然后若此牌目标数大于1，此技能本回合失效。",
  ["weituo"] = "委托",
  [":weituo"] = "其他角色出牌阶段限一次，其可以选择一名其他角色，然后交给你等同于选择角色体力值的手牌，使其于本轮内成为【委托目标】。当你发动【魔弹】时，若场上有【委托目标】，则可选择的角色必须为【委托目标】。",
  ["#modan-choose"] = "魔弹：请选择一名目标",

  ["weituo&"] = "委托",
  ["#weituo&"] = "选择一名其他角色并交出等同于选择角色体力值的手牌，使其成为【委托目标】",
  ["@@weituo_target-round"] = "委托目标",
}

return p